home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 April: Mac OS SDK / Dev.CD Apr 99 SDK1.toast / Development Kits / ColorSync 2.5.1 SDK / Sample Code / CSDemo 2.5 / ShellSources / trapUtils.c < prev    next >
Encoding:
Text File  |  1998-09-09  |  3.1 KB  |  98 lines  |  [TEXT/CWIE]

  1. // Simple framework for Macintosh sample code
  2. // This file contains the trap detection related code code for the framework.
  3. // 
  4. // 9/16/94    david    first cut
  5. // 9/20/95    david    improved comments
  6.  
  7. #include <Types.h>
  8. #include <Traps.h>
  9. #include <Patches.h>
  10. #include <OSUtils.h>
  11. #include <Gestalt.h>
  12.  
  13. #include "trapUtils.h"
  14.  
  15.     
  16. /**\
  17. |**| ==============================================================================
  18. |**| PRIVATE FUNCTION PROTOTYPES
  19. |**| ==============================================================================
  20. \**/
  21. short         NumToolboxTraps        ( void ) ;
  22. TrapType    GetTrapType            ( short theTrap ) ;
  23.  
  24.  
  25. /**\
  26. |**| ==============================================================================
  27. |**| PUBLIC FUNCTIONS
  28. |**| ==============================================================================
  29. \**/
  30.  
  31.  
  32. /*------------------------------------------------------------------------------*\
  33.     TrapAvailable
  34.  *------------------------------------------------------------------------------*
  35.         This function determines a traps is available on the user machine.
  36.         This function should only be used in cases where that Gestalt Manager
  37.         cannot be used to determine if a function is available.  (For example,
  38.         there is no way to detimine if the _Gestalt or _WaitNextEvent traps are
  39.         available by calling Gestalt )
  40. \*------------------------------------------------------------------------------*/
  41. Boolean    TrapAvailable ( short theTrap )
  42. {
  43.     TrapType tType;
  44.     Boolean isAvail;
  45.     
  46.     tType = GetTrapType(theTrap) ;
  47.     if (tType == kToolboxTrapType)
  48.     {
  49.         theTrap &= 0x07FF;
  50.         if (theTrap >= NumToolboxTraps() )
  51.             theTrap = _Unimplemented ;
  52.     }
  53.     
  54.     isAvail = NGetTrapAddress(theTrap, tType) !=
  55.               GetToolboxTrapAddress(_Unimplemented) ;
  56.     return isAvail;
  57. }
  58.  
  59.  
  60. /**\
  61. |**| ==============================================================================
  62. |**| PRIVATE FUNCTIONS
  63. |**| ==============================================================================
  64. \**/
  65.  
  66.  
  67. /*------------------------------------------------------------------------------*\
  68.     NumToolboxTraps
  69.  *------------------------------------------------------------------------------*
  70.         This function determines the number of toolbox traps (0x0200 or 0x0400).
  71.         This function relies on the fact the _InitGraf trap (0xA86E) is always
  72.         implimented.  If the trap dispatch table has more than 0x0200 entries
  73.         then 0xAA6E is either unimplimented or not the same as the trap address
  74.         of _InitGraf
  75. \*------------------------------------------------------------------------------*/
  76. static short NumToolboxTraps ( void )
  77. {
  78.     if (GetToolboxTrapAddress(_InitGraf) == GetToolboxTrapAddress(0xAA6E))
  79.         return 0x0200 ;
  80.     else
  81.         return 0x0400 ;
  82. }
  83.  
  84.  
  85. /*------------------------------------------------------------------------------*\
  86.     GetTrapType
  87.  *------------------------------------------------------------------------------*
  88.         This function determines the type of trap (toolbox or os ).
  89. \*------------------------------------------------------------------------------*/
  90. static TrapType GetTrapType ( short theTrap )
  91. {
  92.     if ((theTrap & 0x0800) > 0)
  93.         return kToolboxTrapType ;
  94.     else
  95.         return kOSTrapType ;
  96. }
  97.  
  98.